package lib.player.items;

import java.awt.Color;
import java.awt.Image;

import lib.Commands;
import lib.Universe;
import lib.Utils;
import lib.map.Map;
import lib.player.Player;
import lib.player.PlayerList;

public class Item {
	Utils util=new Utils();
	public String Name = "None";
	public Image[] Textures = new Image[1];
	public int damage = 1;
	public int NR=0;
	public boolean win=false;
	public Color color=new Color(0,0,0,0);

	public Item( String Name, int damage, String[] Sources) {
		this.Name = Name;
		this.damage = damage;
		Textures = util.imageLodaer(Sources);
	}

	public Item( String Name) {
		this.Name = Name;

	}

	public Item() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 * @param val
	 *            Phase for animation
	 * @return Image
	 */

	public Image getTexture(int val) {
		return Textures[val % Textures.length];
	}

	public String toString() {
		return String.valueOf(NR);
	}

	public void respwan(Map map, Player player, Universe uni, PlayerList list,
			int fuzz) {
		if (player.ITEM.NR!=0) {
			int x;
			int y;
			do {
				x = (int)(player.xPos +  Math.random() * fuzz * 10*Math.pow(-1,(int)(Math.random()*2)));
				y =  (int)( player.yPos +Math.random() * fuzz * 10*Math.pow(-1,(int)(Math.random()*2)));
			} while (map.checkCollision(x, y, 0));
			map.setField(player.ITEM.NR, x / 10, y / 10);
			uni.broadcast(Commands.SETMAP,false+" "+ player.ITEM.NR + " "
					+ x/10 + " " + y/10);
			player.ITEM = list.parser.items.get(0);
			uni.broadcast(Commands.ITEM, player.nr + " "+0);
		}
	}

}
